// Pages/changemyinfo/changemyinfo.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    which:'',
    alldata:[],
    show:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this
    let data=JSON.parse( options.alldata)

    that.setData({
      which:options.id,
      alldata:data
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log(this.data.which)
    if(this.data.which==1){
      this.setData({
        show:this.data.alldata.account
      })
      }else
      if (this.data.which == 2) {
        console.log("2222")
        this.setData({
          show: this.data.alldata.name
        })
      }
      else if (this.data.which == 3) {
          this.setData({
            show: this.data.alldata.mobile
          })
        }
       else   if (this.data.which == 4) {
            this.setData({
              show: this.data.alldata.weixin
            })
          }
           else if (this.data.which == 5) {
              this.setData({
                show: this.data.alldata.department
              })
            }
           else   if (this.data.which == 6) {
                this.setData({
                  show: this.data.alldata.grade
                }) 
                }
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },
  updata:function(){
      var that=this
      let token=wx.getStorageSync("token")
    wx.request({
      url: 'http://47.103.21.65:5645/user/updateMyself',
      method:"post",
      data:{

        account:that.data.which==1?that.data.show:that.data.alldata.account,
        name: that.data.which == 2 ? that.data.show : that.data.alldata.name,
        mobile: that.data.which == 3 ? that.data.show : that.data.alldata.mobile,
        weixin: that.data.which == 4 ? that.data.show : that.data.alldata.weixin,
        grade: that.data.which == 5 ? that.data.show : that.data.alldata.grade,
        department: that.data.which == 6 ? that.data.show : that.data.alldata.department,
      },
      header:{
        'content-type': 'application/x-www-form-urlencoded',
        'token':token
      },
      success:function(res){
        console.log(res)
      },
      fail:function(res){
        console.log(res)
      }
    })

  },
  indata:function(res){
    this.setData({
      show:res.detail.value
    })
  },
  close:function(){
    wx.navigateBack({
      
    })
  }
})